<?php
require("includes/dbInfo.php");

//get page name to edit from URL - corresponds to "url" in htmlPages table
$pageToEdit = $_GET['page'];
    
//check if form is being submitted, otherwise continue
if ($_POST['editor']) {
    //update the database with the submitted HTML code
    mysql_query("UPDATE htmlPages SET html = '" . $_POST['editor'] . "' WHERE url = '" . $pageToEdit . "'")
        or die(mysql_error());
    //display success message
    ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<title>LazySwim</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="style_ie.css" /><![endif]-->
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="style_ie6.css" /><![endif]-->
</head>
<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
                <div id="header-menu">
                    <ul>
                        <li class="page_item"><a href="index.php">Home</a></li>
                        <li class="page_item"><a href="generalinfo.php">General Info</a></li>
                        <li class="page_item"><a href="aboutteam.php">About Team</a></li>
                        <li class="page_item"><a href="programs.php">Programs</a></li>
                        <li class="page_item"><a href="meetsandevents.php">Meets and Events</a></li>
                        <li class="page_item"><a href="digitalmedia.php">Digital Media</a></li>
                    </ul>
                </div>
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
                    <ul>
                        <li class="cat-item"><a href="login-public.php">Swimmer/Parent Login</a></li>
                        <li class="cat-item"><a href="login-manager.php">Manager Login</a></li>
                    </ul>
                </div>
            </div>
            <div id="main">

                <div id="sidebar">
                    <?php
					// include the corresponding navigation page
                    include("navigation-public.php");
					?>     
                </div>

<!-- main body -->

                <div class="featured-post">
                    <div class="post-title">
                        <h2>Edit Successful</h2>
                    </div>
                    <div class="post-entry">
                        <p>The page was edited successfully.</p>
                        <p><a href = "javascript:history.back()">Back to editing page</a></p>
                    </div>
                </div>

                <div class="clear"></div>

            </div>
            <div id="footer"> Copyright 2011 - All Rights Reserved<br />
                Designed by <a href="http://wpjunction.com/">HPA</a> // CMPUT 410 Project by Kim Beaudin, Raymond Ta, Frederick Vuong, Ashton Wong<br />
                Valid XHTML and CSS </div>
        </div>
    </div>
</div>
</body>
</html>

<?php
}
else {
    //die if there is no page name specified
    if (!isset($pageToEdit)) {
        die('ERROR: No page specified to edit.');
    }
    else {

        $page_sql = mysql_query("SELECT html from htmlPages where url = '$pageToEdit'") 
            or die(mysql_error());

    // show the WYSIWYG editor with contents of the specified page name
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<title>LazySwim - General Info</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="style_ie.css" /><![endif]-->
<!--[if lt IE 7]><link rel="stylesheet" type="text/css" href="style_ie6.css" /><![endif]-->
<!-- TinyMCE -->
<script type="text/javascript" src="includes/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
	
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,|,print,|,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

	});
</script>
<!-- /TinyMCE -->

</head>
<body>
<div id="page">
    <div id="page-top">
        <div id="page-bottom">
          <div id="header">
                <div id="header-info">
                    <h1>LAZYSWIM</h1>
                    <div class="description">Simplistic Swim System</div>
                </div>
                <div id="header-menu">
                    <ul>
                        <li class="page_item"><a href="index.php">Home</a></li>
                        <li class="page_item"><a href="generalinfo.php">General Info</a></li>
                        <li class="page_item"><a href="aboutteam.php">About Team</a></li>
                        <li class="page_item"><a href="programs.php">Programs</a></li>
                        <li class="page_item"><a href="meetsandevents.php">Meets and Events</a></li>
                        <li class="page_item"><a href="digitalmedia.php">Digital Media</a></li>
                    </ul>
                </div>
                <div id="header-date">Today is <?php echo date('l, F jS, Y'); ?></div>
                <div id="header-cats">
                    <ul>
                        <li class="cat-item"><a href="login-public.php">Swimmer/Parent Login</a></li>
                        <li class="cat-item"><a href="login-manager.php">Manager Login</a></li>
                    </ul>
                </div>
            </div>
            <div id="main">

                <div id="sidebar">
                    <?php
					// include the corresponding navigation page
                    include("navigation-public.php");
					?>     
                </div>

<!-- main body -->

                <div class="featured-post">
                    <div class="post-title">
                        <h2><font color="#CC6600">EDITING:</font> <?php echo strToUpper($pageToEdit); ?></h2>
                    </div>
                    <div class="post-entry">
                    <form method="post" action="editpage.php?page=<?php echo $pageToEdit; ?>">                    
                        <p>Please use the editor below to make changes to the page.</p>
                    
                        <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
                        <textarea id="editor" name="editor" rows="15" cols="80" style="width: 40%">
                        <?php
                        //display HTML code stored in database for this page
                        while( $row = mysql_fetch_array($page_sql)) {
                            echo $row[html];
                        }
                        ?> 
                        </textarea>
                    
                        <br />
                        <input type="submit" name="save" value="Submit" />
                        <input type="reset" name="reset" value="Reset" />
                    </form>
                    </div>
                </div>

<!-- end of one post -->

             
                <div class="clear"></div>

            </div>
            <div id="footer"> Copyright 2011 - All Rights Reserved<br />
                Designed by <a href="http://wpjunction.com/">HPA</a> // CMPUT 410 Project by Kim Beaudin, Raymond Ta, Frederick Vuong, Ashton Wong<br />
                Valid XHTML and CSS </div>
        </div>
    </div>
</div>
</body>
</html>
<?php
            } //end of else
    } //end of else
?>